$(function () {
    $('#keyword').keypress(function (e) {
        var key = e.which; //e.which是按键的值
        if (key == 13) {
            var q = $(this).val();
            if (q && q != '') {
                window.location.href = '/goods/search/' + q;
            }
        }
    });


    //搜索建议：在搜索框输入关键词时，下方出现相关搜索建议
    $('#keyword').keyup(function(e){
        var param = {"keywords":$('#keyword').val()}
        $.ajax({
            url: '/goods/searchSuggestion',
            type: 'POST',
            contentType: "application/json",
            data: JSON.stringify(param),
            // data: param,
            // datatype: 'json',
            success: function (res) {
                if (res.code == 200) {
                    var list = res.data;
                    var suggestions = '';
                    for (var i = 0; i < list.length; i++) {
                        suggestions += list[i]+',';
                    }
                    console.log("suggestions:"+suggestions);
                }
            }
        });
    });
});

function search() {
    var q = $('#keyword').val();
    if (q && q != '') {
        window.location.href = '/goods/search/' + q;
    }
}
